import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
import { Loading } from 'element-ui';

Vue.config.productionTip = false;
Vue.use(ElementUI);
// 全局配置axios
// axios.defaults.baseURL = 'https://www.escook.cn';
axios.defaults.baseURL = 'http://localhost:3000';
Vue.prototype.$http = axios;

// 拦截器
let LoadingInstance = null;
axios.interceptors.request.use(config => {
  LoadingInstance = Loading.service({ fullscreen: true });
  return config;
});
// 想要拦截器
axios.interceptors.response.use(response => {
  LoadingInstance.close();
  return response;
});

Vue.filter('dataFormat', dtStr => {
  const dt = new Date(dtStr);
  const y = dt.getFullYear();
  const m = padZero(dt.getMonth() + 1);
  const d = padZero(dt.getDate());
  const hh = padZero(dt.getHours());
  const mm = padZero(dt.getMinutes());
  const ss = padZero(dt.getSeconds());
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
});
function padZero(n) {
  return n > 9 ? n : '0' + n;
}

new Vue({
  render: h => h(App),
  router,
}).$mount('#app');
